package cn.gjxblog.core.event.spring;

import cn.gjxblog.core.event.spring.demo2.MyAppEvent;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 *  验证 @EventListener 中的属性 condition
 */
@Component
public class AnnotationDrivenEventListenerTests {
    AnnotationConfigApplicationContext annotationConfigApplicationContext;

    @Before
    public void init(){
        annotationConfigApplicationContext = new AnnotationConfigApplicationContext(AnnotationDrivenEventListenerTests.class);
    }

    @Test
    public void test(){
//        System.out.println(annotationConfigApplicationContext.getBean("name"));
    }


    @Component
    public static class MyEventListener{
        @EventListener(value = {ContextRefreshedEvent.class, MyAppEvent.class},condition = "#root.args == null")
        public void handle(Object o){
            System.out.println(o);
            System.out.println("事件来了");
        }
    }


}
